package com.book.service.impl;

import com.book.dao.DataDao;
import com.book.service.DataService;
import com.book.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//错误码14001开始
@Service
public class DataServiceImpl implements DataService {
    @Autowired
    private DataDao dataDao;

    //按照月份和年份来统计销售金额
    @Override
    public ResponseResult getPriceByMonth(int year) {
        try {
            return new ResponseResult(200,"获取数据成功",dataDao.getPriceByMonth(year));
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseResult(14001,"获取数据失败");
        }
    }


    //按照季度来统计销售金额
    @Override
    public ResponseResult getPriceByQuarter(int year) {
        try {
            return new ResponseResult(200,"获取数据成功",dataDao.getPriceByQuarter(year));
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseResult(14002,"获取数据失败");
        }
    }

    //相同年月统计销售数量前10的书籍，注意这里是两个参数
    @Override
    public ResponseResult getAmountSameDate(String year, String month) {
        try {
//            System.out.println(year);
//            System.out.println(month);
            return new ResponseResult(200,"获取数据成功",dataDao.getAmountSameDate(year,month));
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseResult(14003,"获取数据失败");
        }
    }

    //统计不同年月统计销售数量前10的书籍，注意这里有四个参数
    @Override
    public ResponseResult getAmountNoSameDate(String startYear, String startMonth, String endYear, String endMonth) {
        try {
            return new ResponseResult(200,"获取数据成功",dataDao.getAmountNoSameDate(startYear,startMonth,endYear,endMonth));
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseResult(14004,"获取数据失败");
        }
    }
}
